import axios from 'axios'
import './request'

export function getInfo (params) {
  return axios.get('api/datav/jobs', params)
}

class JobServ {
  constructor () {
    this.kwList = [
      '消防教官', '消防宣讲员', '健身教练', '形象保安', '拓展教官',
      '安保经理', '司机', '物业', '拓展培训'
    ]
    this.kwIndex = 0
    this.page = 1
    this.perPage = 20
  }

  get currKw () {
    return this.kwList[this.kwIndex]
  }

  next (kwSearchHasNext) {
    if (kwSearchHasNext) {
      this.page += 1
    } else {
      this.page = 1
      this.kwIndex = (this.kwIndex + 1) % this.kwList.length
    }
  }

  fetch () {
    return new Promise((resolve, reject) => {
      axios.get('api/datav/jobs', {
        params: {
          kw: this.currKw,
          page: this.page
        }
      }).then(res => {
        if (res.code === 0) {
          resolve(res.data)
        } else {
          reject(res)
        }
      })
    })
  }
}

export {
  JobServ
}
